class Solution {
public:
	int longestConsecutive(vector<int>& nums) {
		int maxLen = 0;
		unordered_map<int, int> mp;
		for (int num : nums)
		{
			mp[num] = num;
		}
		for (int i = nums.size() - 1; i >= 0; i--)
		{
			if (!mp.count(nums[i] - 1)) {
				int cur = nums[i];
				while (mp.count(cur + 1)) {
					cur++;
				}
				maxLen = max(maxLen, cur - nums[i] + 1);
			}
		}

		return maxLen;
	}
};